package com.ruoyi.manage.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.manage.domain.request.PasswordModificationRequest;
import com.ruoyi.manage.service.IAppPasswordModificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @Author: wwy
 * @Date: 2021/1/6 16:19
 */
@Service
public class AppPasswordModificationServiceImpl implements IAppPasswordModificationService {

    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public AjaxResult passwordModification(PasswordModificationRequest passwordModificationRequest) {
       /* if(passwordModificationRequest == null || StringUtils.isEmpty(passwordModificationRequest.getPhone()) || StringUtils.isEmpty(passwordModificationRequest.getVerificationCode())){
            throw new CustomException("参数错误", HttpStatus.BAD_REQUEST);
        }
        //验证账号是否重复
        Member byPhone = memberMapper.findByPhone(passwordModificationRequest.getPhone());
        if(byPhone == null){
            return AjaxResult.error("账号不存在");
        }
        //短信登录
        Object verificationCodeCache = redisTemplate.opsForValue().get(ManageRedisConstants.RETRIEVE_CODE + passwordModificationRequest.getPhone());
        if(verificationCodeCache != null){
            String verificationCodeCacheStr = String.valueOf(verificationCodeCache);
            if(verificationCodeCacheStr.equals(passwordModificationRequest.getVerificationCode())){
                //验证码正确,修改密码
                try {
                    byPhone.setPassword(Md5Utils.encoderByMd5(passwordModificationRequest.getPassword()));
                    memberMapper.updateMember(byPhone);
                    return AjaxResult.success("修改密码成功");
                } catch (NoSuchAlgorithmException e) {
                    e.printStackTrace();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }


            }else{
                throw new CustomException("验证码错误",HttpStatus.ERROR);
            }
        }
        return AjaxResult.error("修改密码失败");*/
       return null;
    }
}
